#include "wl_semaphore.h"
#include "ql_rtos.h"
#include "wl_trace.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

wl_int32 wl_semaphore_create(const wl_char* name, OUT WL_SEMAPHORE* semaphore, wl_uint32 init_count) {
    if (wl_null != semaphore) {
        return ql_rtos_semaphore_create(semaphore, init_count);
    }
    return -1;
}

wl_int32 wl_semaphore_wait(WL_SEMAPHORE* semaphore) {
    if (wl_null != semaphore) {
        return ql_rtos_semaphore_wait(*semaphore, QL_WAIT_FOREVER);
    }

    return -1;
}

wl_int32 wl_semaphore_try_wait(WL_SEMAPHORE* semaphore, wl_uint32 timeout) {
    if (wl_null != semaphore) {
        return ql_rtos_semaphore_wait(*semaphore, timeout);
    }
    return -1;
}

wl_int32 wl_semaphore_post(WL_SEMAPHORE* semaphore) {
    if (wl_null != semaphore) {
        return ql_rtos_semaphore_release(*semaphore);
    }
    return -1;
}

wl_int32 wl_semaphore_delete(WL_SEMAPHORE* semaphore) {
    if (wl_null != semaphore) {
        return ql_rtos_semaphore_delete(*semaphore);
    }
    return -1;
}

#ifdef __cplusplus
}
#endif /* __cplusplus */
